/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package presenter;

import view.TelaMenuPrincipal;
import logs.Log;
import persistencia.Pacientes;
import grafico.GraficoCC;
import grafico.GraficoIAC;
import grafico.GraficoIMC;
import grafico.GraficoRCQ;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JOptionPane;
import model.Paciente;
import observer.Observador;
import propriedadesLog.PropriedadesLog;

/**
 *
 * @author KDC
 */
public class MenuPrincipalPresenter implements Observador {

    Log log;
    PacientePresenter cPaciente;
    Pacientes pacientes;
    PropriedadesLog propertiesLog;
    TelaMenuPrincipal view;
    Paciente paciente = null;

    public MenuPrincipalPresenter() {
        pacientes = new Pacientes();
        cPaciente = new PacientePresenter(pacientes);
        view = new TelaMenuPrincipal();
        propertiesLog = new PropriedadesLog();

//        try {
//            log = propertiesLog.pegarLog();
//
//        } catch (Exception ex) {
//            Logger.getLogger(TelaMenuPrincipal.class.getName()).log(Level.SEVERE, null, ex);
//        }

        pacientes.registrarObservador(this);

        view.setVisible(true);
        view.setLocationRelativeTo(null);
        view.getLbNPac().setText(String.valueOf(cPaciente.qtdPacientes()));

        view.getjShowPacientes().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                ListarPacientesPresenter listar = new ListarPacientesPresenter(log, cPaciente);
            }
        });

        view.getjMenuItem3().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                view.dispose();
            }
        });

        view.getjCadPaciente().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                new CadPacientePresenter(null, cPaciente, log);
            }
        });

        view.getConfigLog().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                configLog();
            }
        });

        view.getjMenu1().addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent me) {
                super.mouseClicked(me); //To change body of generated methods, choose Tools | Templates.
                 verificaLog();
            }

        });
        
        view.getjMenu2().addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent me) {
                super.mouseClicked(me); //To change body of generated methods, choose Tools | Templates.
                 verificaLog();
            }

        });
        
        view.getjMenu5().addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent me) {
                super.mouseClicked(me); //To change body of generated methods, choose Tools | Templates.
                 verificaLog();
            }

        });

        view.getMenuGraficoIMC().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                GraficoIMC graficoIMC = new GraficoIMC(pacientes);
            }
        });

        view.getMenuGraficoIAC().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                GraficoIAC graficoIAC = new GraficoIAC(pacientes);
            }
        });

        view.getMenuGraficoRCQ().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                GraficoRCQ graficoRCQ = new GraficoRCQ(pacientes);
            }
        });

        view.getMenuGraficoCC().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                GraficoCC graficoCC = new GraficoCC(pacientes);
            }
        });

    }
    
    public void configLog(){
        ConfigLogPresenter configLog = new ConfigLogPresenter(this);
    }

    public TelaMenuPrincipal getView() {
        return view;
    }

    public void setView(TelaMenuPrincipal view) {
        this.view = view;
    }

    public void verificaLog() {
        if (log == null) {
            JOptionPane.showMessageDialog(view, "Selecionar Tipo de Log Primeiro!");
        }
    }

    public Log getLog() {
        return log;
    }

    public void setLog(Log log) {
        this.log = log;
    }

    @Override
    public void atualizar() {

        view.getLbNPac().setText(String.valueOf(cPaciente.qtdPacientes()));

    }

}
